|
12. Reducing Size |
|
|
When you create a portable you should pay attention to its size. If you want to put it on your USB stick, it should be as small as possible but also should be fully functional.
The most obvious way to reduce size is to delete some irrelevant files. Usually there are some files in a program's directory which are not needed to run the program. You may delete them but make sure that you delete only those files which the program doesn't need.
These files may be:
Another way to reduce size is using UPX.
UPX is a free, portable, extendable, high-performance executable packer for several different executable formats. It achieves an excellent compression ratio and offers very fast decompression. Your executables suffer no memory overhead or other drawbacks because of in-place decompression.
The beauty of upx is that it compresses .exe, .ocx, .dll and .com files with an excellent ratio and these files can be launched directly after compression. So, you may reduce a size of an executable that was originally 2 MB to 1 MB and it remains usable.
Although upx is a very nice tool to reduce file size you must use it with care. Some programs won't accept upx-ed files so always backup them before compressing them. If the programs starts up as expected you should thoroughly test to make sure every function of the program is working properly. My experience is that compressing .exe files is safe, if they run after compressing they'll probably run without any problems. But compressing .dll, .ocx and .com files is not so obvious so you should test them.
The NSIS script has a line that says:
;-----Runtime switches---- CRCCheck off
This disables CRC check so the launcher will not check if its size is the same as it was when creating it. If you change it to "CRCCheck on" and compress it with upx, you'll get an error when you try to launch the resulting .exe file:
NSIS Error
The installer you are trying to use is corrupted or incomplete. This could be the result of a damaged disk, a failed download or a virus. You may want to contact the author of this installer to obtain a new copy. It may be possible to skip this check using the /NCRC command line switch (NOT RECOMMENDED).
If you want to protect your portable launcher, use "CRCCheck on". If a virus modifies the size of the launcher it simply will not run and thus protects your computer from being infected. And because your portable may travel from one computer to another it is greatly exposed to virus attacks.
Until now I did compress my launchers with upx because I was a brave man. But as I reread my last few lines I thought I shouldn't be so brave...
You can find upx in directory "Tools\UPX 2.03" so you do not need to download it. But I recommend to check if there's a newer version available before using it.
You can see in its website how to use UPX from command line. Here's an example for compressing "toobigfile.dll" (with maximum compression):
"D:\Tools\UPX\upx.exe" -9 "H:\Data\toobigfile.dll"
And another one for decompressing:
"D:\Tools\UPX\upx.exe" -d "H:\Data\toobigfile.dll"
To compress files with upx I use it from command line but I created a context menu with PowerPro so I only have to select files and select "Compress with UPX" or "Uncompress with UPX" from the context menu. It is not a built-in feature but you should add it manually. I won't discuss PowerPro here; see the website or its forum for more info about it.
Using it from command line is somewhat cumbersome if you have a large number of files to compress so I recommend you to use a GUI for that like UPX Mass Compressor, UPX Shell, UPX-it or other tools. Unfortunately from this list only UPX Mass Compressor has the ability to compress several files at once but maybe you'll find another great GUI for it on the net. |
|